export default function (path) {
  let base = '';

  return {
    configResolved(config) {
      base = config.base;
    },
    transform(code, id) {
      // if (id.indexOf('.vue') === -1 && id.indexOf('.ts') === -1) {
      //   return code;
      // }
      const isDev = process.env.VITE_USER_NODE_ENV === 'development';
      const replacer = isDev ? '/' : path || base;
      return code.replace(/\[publicPath\]/g, replacer);
    },
    enforce: 'pre'
  };
}
